package com.haois.mp.database.interceptor.configuration;

import com.haois.mp.database.interceptor.SysInterceptor;
import com.haois.mp.wechat.util.WxOAuth2AccessTokenUtil;
import com.haois.mp.database.module.common.service.IUserTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by RuiHaoZ on 2018/1/28 16:26
 */
@Configuration
public class SysInterceptorConfiguration extends WebMvcConfigurerAdapter {

    @Autowired
    private IUserTokenService iUserTokenService;

    @Autowired
    private WxOAuth2AccessTokenUtil wxOAuth2AccessTokenUtil;

    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptorRegistry = registry.addInterceptor(
                new SysInterceptor(iUserTokenService, wxOAuth2AccessTokenUtil));
        interceptorRegistry.addPathPatterns("/RuiHaoZ");
        interceptorRegistry.excludePathPatterns("");
        PathMatcher pathMatcher = new AntPathMatcher("RuiHaoZ");
        interceptorRegistry.pathMatcher(pathMatcher);
    }
}
